<template>
  <j-form-container :disabled="disabled">
    <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
      <a-row>
        <!-- <a-col :span="8">
            <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectCode">
              <a-input v-model="model.projectCode" placeholder="请输入项目编号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderProjectCode">
              <a-input v-model="model.tenderProjectCode" placeholder="请输入招标项目编号"></a-input>
            </a-form-model-item>
          </a-col> -->
        <!-- <a-col :span="8">
          <a-form-model-item
            label="统一交易标识码"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="unifiedDealCode"
          >
            <a-input v-model="model.unifiedDealCode" placeholder="请输入统一交易标识码"></a-input>
          </a-form-model-item>
        </a-col> -->
        <!-- <a-col :span="8">
          <a-form-model-item
            label="招标项目名称"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="tenderProjectName"
          >
            <a-input v-model="model.tenderProjectName" placeholder="请输入招标项目名称"></a-input>
          </a-form-model-item>
        </a-col> -->
        <a-col :span="8">
          <a-form-model-item
            label="项目行业分类"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="tenderProjectIndustriesType"
          >
            <!-- <j-dict-select-tag
              type="list"
              v-model="model.tenderProjectIndustriesType"
              dictCode="sys_industry_category"
              placeholder="请选择招标项目行业分类"
            /> -->
            <j-category-select v-model="model.tenderProjectIndustriesType" pcode="A04"/>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="招标项目类型"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="tenderProjectType"
          >
            <j-dict-select-tag
              type="list"
              v-model="model.tenderProjectType"
              dictCode="sys_project_type"
              placeholder="请选择招标项目类型"
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="招标主体性质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entityType">
            <j-dict-select-tag
              type="list"
              v-model="model.entityType"
              dictCode="sys_investment_subject"
              placeholder="请选择招标主体性质"
            />
          </a-form-model-item>
        </a-col>
        <!-- <a-col :span="8">
          <a-form-model-item
            label="招标项目所在行政区域代码"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="regionCode"
          >
            <j-dict-select-tag
              type="list"
              v-model="model.regionCode"
              dictCode="sys_kf_area"
              placeholder="请选择招标项目所在行政区域代码"
            />
          </a-form-model-item>
        </a-col> -->
        <a-col :span="24">
          <a-form-model-item
            label="招标范围"
            :labelCol="{ lg: { span: 3 }, sm: { span: 4 } }"
            :wrapperCol="{ lg: { span: 21 }, sm: { span: 20 } }"
            prop="tenderContent"
          >
            <a-textarea v-model="model.tenderContent" rows="4" placeholder="请输入招标范围" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="项目业主名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerName">
            <a-input v-model="model.ownerName" placeholder="请输入项目业主名称"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="招标人名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tendererName">
            <a-input v-model="model.tendererName" placeholder="请输入招标人名称"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="招标人类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tendererCodeType">
            <j-dict-select-tag dictCode="tenderer_code_type" type="list" v-model="model.tendererCodeType" placeholder="请输入招标人类别" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="招标人代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tendererCode">
            <a-input v-model="model.tendererCode" placeholder="请输入招标人代码"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="招标人角色" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tendererRole">
            <a-input v-model="model.tendererRole" placeholder="请输入招标人角色"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="招标代理机构名称"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="tenderAgencyName"
          >
            <a-input v-model="model.tenderAgencyName" placeholder="请输入招标代理机构名称"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="招标代理机构类别"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="tenderAgencyCodeType"
          >
            <j-dict-select-tag dictCode="tender_agency_code_type" type="list" v-model="model.tenderAgencyCodeType" placeholder="请选择招标代理机构类别" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="招标代理机构代码"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="tenderAgencyCode"
          >
            <a-input v-model="model.tenderAgencyCode" placeholder="请输入招标代理机构代码"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="招标代理机构角色"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="tenderAgencyRole"
          >
            <a-input v-model="model.tenderAgencyRole" placeholder="请输入招标代理机构角色"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="招标方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderMode">
              <a-radio-group v-model="model.tenderMode" placeholder="请输入招标方式">
                  <a-row>
                    <a-radio value="1">公开</a-radio>
                    <a-radio value="0">邀请</a-radio>
                  </a-row>
                </a-radio-group>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="招标组织形式"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="tenderOrganizeForm"
          >
            <a-input v-model="model.tenderOrganizeForm" placeholder="请输入招标组织形式"></a-input>
          </a-form-model-item>
        </a-col>
        <!-- <a-col :span="8">
          <a-form-model-item
            label="监督部门名称"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="superviseDeptName"
          >
            <a-input v-model="model.superviseDeptName" placeholder="请输入监督部门名称"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="监督部门代码"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            prop="superviseDeptCode"
          >
            <a-input v-model="model.superviseDeptCode" placeholder="请输入监督部门代码"></a-input>
          </a-form-model-item>
        </a-col> -->
        <!-- <a-col :span="8">
          <a-form-model-item label="审核部门名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approveDeptName">
            <a-input v-model="model.approveDeptName" placeholder="请输入审核部门名称"></a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="审核部门代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approveDeptCode">
            <a-input v-model="model.approveDeptCode" placeholder="请输入审核部门代码"></a-input>
          </a-form-model-item>
        </a-col> -->
        <a-col :span="8">
          <a-form-model-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachmentCode">
            <j-upload v-model="model.attachmentCode"></j-upload>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="交易系统标识码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformCode">
            <a-input v-model="model.platformCode" placeholder="请输入交易系统标识码"></a-input>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </j-form-container>
</template>
<script>
import { getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
export default {
  name: 'ExTenderProjectForm',
  components: {},
  props: {
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 9 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 15 },
      },
      validatorRules: {
        projectCode: [{ required: true, message: '请输入项目编号!' }],
        tenderProjectCode: [{ required: true, message: '请输入招标项目编号!' }],
        unifiedDealCode: [{ required: true, message: '请输入统一交易标识码!' }],
        tenderProjectName: [{ required: true, message: '请输入招标项目名称!' }],
        tenderProjectIndustriesType: [{ required: true, message: '请输入招标项目行业分类!' }],
        //  tenderProjectType: [
        //     { required: true, message: '请输入招标项目类型!'},
        //  ],
        //  entityType: [
        //     { required: true, message: '请输入招标主体性质!'},
        //  ],
        //  regionCode: [
        //     { required: true, message: '请输入招标项目所在行政区域代码!'},
        //  ],
        //  tenderContent: [
        //     { required: true, message: '请输入招标内容与范围及招标方案说明!'},
        //  ],
        //  tendererName: [
        //     { required: true, message: '请输入招标人名称!'},
        //  ],
        //  tendererCodeType: [
        //     { required: true, message: '请输入招标人类别!'},
        //  ],
        //  tendererCode: [
        //     { required: true, message: '请输入招标人代码!'},
        //  ],
        //  tendererRole: [
        //     { required: true, message: '请输入招标人角色!'},
        //  ],
        //  tenderMode: [
        //     { required: true, message: '请输入招标方式!'},
        //  ],
        //  tenderOrganizeForm: [
        //     { required: true, message: '请输入招标组织形式!'},
        //  ],
        //  superviseDeptName: [
        //     { required: true, message: '请输入监督部门名称!'},
        //  ],
        //  approveDeptName: [
        //     { required: true, message: '请输入审核部门名称!'},
        //  ],
        //  platformCode: [
        //     { required: true, message: '请输入交易系统标识码!'},
        //  ],
      },
      confirmLoading: false,
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    initFormData(url, id) {
      this.clearFormData()
      if (!id) {
        this.edit(this.modelDefault)
      } else {
        getAction(url, { id: id }).then((res) => {
          if (res.success) {
            let records = res.result
            if (records && records.length > 0) {
              this.edit(records[0])
            }
          }
        })
      }
    },
    edit(record) {
      this.model = Object.assign({}, record)
      console.log('ExTenderProjectForm-edit', this.model)
    },
    getFormData() {
      let formdata_arr = []
      this.$refs.form.validate((valid) => {
        if (valid) {
          let isNullObj = true
          Object.keys(this.model).forEach((key) => {
            if (this.model[key]) {
              isNullObj = false
            }
          })
          if (!isNullObj) {
            formdata_arr.push(this.model)
          }
        } else {
          this.$emit('validateError', '招标项目表单校验未通过')
        }
      })
      return formdata_arr
    },
    validate(index) {
      return new Promise((resolve, reject) => {
        // 验证主表表单
        this.$refs.form.validate((valid) => {
          !valid ? reject({ error: VALIDATE_NO_PASSED, index }) : resolve()
        })
      })
        .then((values) => {
          return Promise.resolve()
        })
        .catch((error) => {
          return Promise.reject(error)
        })
    },
    validate2() {
      this.$refs.form.validate((valid) => {
        return valid
      })
    },
    clearFormData() {
      this.$refs.form.clearValidate()
    },
  },
}
</script>
